use core::{Source, SourceId, SourceMap, Summary, Dependency, PackageId, Package};
use core::PackageSet;
-use util::{CargoResult, ChainError, Config, human, profile};
+use util::{CargoResult, ChainError, Config, human, internal, profile};
/// Source of information about a group of packages.
///
-> CargoResult<PackageSet<'cfg>> {
trace!("getting packages; sources={}", self.sources.len());
- // TODO: Only call source with package ID if the package came from the
- // source
- let mut ret = Vec::new();
-
- for (_, source) in self.sources.sources_mut() {
- try!(source.download(package_ids));
- let packages = try!(source.get(package_ids));
-
- ret.extend(packages.into_iter());
- }
-
- // TODO: Return earlier if fail
- assert!(package_ids.len() == ret.len(),
- "could not get packages from registry; ids={:?}; ret={:?}",
- package_ids, ret);
+ let pkgs = try!(package_ids.iter().map(|id| {
+ let src = try!(self.sources.get_mut(id.source_id()).chain_error(|| {
+ internal(format!("failed to find a source listed for `{}`", id))
+ }));
+ src.download(id)
+ }).collect::<CargoResult<Vec<_>>>());
- Ok(PackageSet::new(ret, self.sources))
+ Ok(PackageSet::new(pkgs, self.sources))
}
fn ensure_loaded(&mut self, namespace: &SourceId, kind: Kind) -> CargoResult<()> {
use url::Url;
-use core::{Summary, Package, PackageId, Registry, Dependency};
+use core::{Package, PackageId, Registry};
use sources::{PathSource, GitSource, RegistrySource};
use sources::git;
use util::{human, Config, CargoResult, ToUrl};
/// The download method fetches the full package for each name and
/// version specified.
- fn download(&mut self, packages: &[PackageId]) -> CargoResult<()>;
-
- /// The get method returns the Path of each specified package on the
- /// local file system. It assumes that `download` was already called,
- /// and that the packages are already locally available on the file
- /// system.
- fn get(&self, packages: &[PackageId]) -> CargoResult<Vec<Package>>;
+ fn download(&mut self, package: &PackageId) -> CargoResult<Package>;
/// Generates a unique string which represents the fingerprint of the
/// current state of the source.
let deps = try!(source.query(&dep));
match deps.iter().map(|p| p.package_id()).max() {
Some(pkgid) => {
- try!(source.download(&[pkgid.clone()]));
- Ok((try!(source.get(&[pkgid.clone()])).remove(0),
- Box::new(source)))
+ let pkg = try!(source.download(pkgid));
+ Ok((pkg, Box::new(source)))
}
None => {
let vers_info = vers.map(|v| format!(" with version `{}`", v))
self.path_source.as_mut().unwrap().update()
}
- fn download(&mut self, _: &[PackageId]) -> CargoResult<()> {
- // TODO: assert! that the PackageId is contained by the source
- Ok(())
- }
-
- fn get(&self, ids: &[PackageId]) -> CargoResult<Vec<Package>> {
- trace!("getting packages for package ids `{:?}` from `{:?}`", ids,
- self.remote);
- self.path_source.as_ref().expect("BUG: update() must be called \
- before get()").get(ids)
+ fn download(&mut self, id: &PackageId) -> CargoResult<Package> {
+ trace!("getting packages for package id `{}` from `{:?}`", id,
+ self.remote);
+ self.path_source.as_mut()
+ .expect("BUG: update() must be called before get()")
+ .download(id)
}
fn fingerprint(&self, _pkg: &Package) -> CargoResult<String> {
Ok(())
}
- fn download(&mut self, _: &[PackageId]) -> CargoResult<()>{
- // TODO: assert! that the PackageId is contained by the source
- Ok(())
- }
-
- fn get(&self, ids: &[PackageId]) -> CargoResult<Vec<Package>> {
- trace!("getting packages; ids={:?}", ids);
+ fn download(&mut self, id: &PackageId) -> CargoResult<Package> {
+ trace!("getting packages; id={}", id);
- Ok(self.packages.iter()
- .filter(|pkg| ids.iter().any(|id| pkg.package_id() == id))
- .cloned()
- .collect())
+ let pkg = self.packages.iter().find(|pkg| pkg.package_id() == id);
+ pkg.cloned().ok_or_else(|| {
+ internal(format!("failed to find {} in path source", id))
+ })
}
fn fingerprint(&self, pkg: &Package) -> CargoResult<String> {
src_path: PathBuf,
config: &'cfg Config,
handle: Option<http::Handle>,
- sources: HashMap<PackageId, PathSource<'cfg>>,
hashes: HashMap<(String, String), String>, // (name, vers) => cksum
cache: HashMap<String, Vec<(Summary, bool)>>,
updated: bool,
config: config,
source_id: source_id.clone(),
handle: None,
- sources: HashMap::new(),
hashes: HashMap::new(),
cache: HashMap::new(),
updated: false,
Ok(())
}
- fn download(&mut self, packages: &[PackageId]) -> CargoResult<()> {
+ fn download(&mut self, package: &PackageId) -> CargoResult<Package> {
let config = try!(self.config());
let url = try!(config.dl.to_url().map_err(internal));
- for package in packages.iter() {
- if self.source_id != *package.source_id() { continue }
- if self.sources.contains_key(package) { continue }
-
- let mut url = url.clone();
- url.path_mut().unwrap().push(package.name().to_string());
- url.path_mut().unwrap().push(package.version().to_string());
- url.path_mut().unwrap().push("download".to_string());
- let path = try!(self.download_package(package, &url).chain_error(|| {
- internal(format!("failed to download package `{}` from {}",
- package, url))
- }));
- let path = try!(self.unpack_package(package, path).chain_error(|| {
- internal(format!("failed to unpack package `{}`", package))
- }));
- let mut src = PathSource::new(&path, &self.source_id, self.config);
- try!(src.update());
- self.sources.insert(package.clone(), src);
- }
- Ok(())
- }
+ let mut url = url.clone();
+ url.path_mut().unwrap().push(package.name().to_string());
+ url.path_mut().unwrap().push(package.version().to_string());
+ url.path_mut().unwrap().push("download".to_string());
+ let path = try!(self.download_package(package, &url).chain_error(|| {
+ internal(format!("failed to download package `{}` from {}",
+ package, url))
+ }));
+ let path = try!(self.unpack_package(package, path).chain_error(|| {
+ internal(format!("failed to unpack package `{}`", package))
+ }));
- fn get(&self, packages: &[PackageId]) -> CargoResult<Vec<Package>> {
- let mut ret = Vec::new();
- for src in self.sources.values() {
- ret.extend(try!(src.get(packages)).into_iter());
- }
- Ok(ret)
+ let mut src = PathSource::new(&path, &self.source_id, self.config);
+ try!(src.update());
+ src.download(package)
}
fn fingerprint(&self, pkg: &Package) -> CargoResult<String> {